<template>
  <div class="settings-container">
    <div class="page-header">
      <h2>系统设置</h2>
    </div>
    
    <a-tabs v-model:activeKey="activeTab">
      <a-tab-pane key="quota" tab="额度设置">
        <div class="quota-settings">
          <!-- 季度额度信息卡片 -->
          <a-card title="季度额度设置" class="quota-card">
            <a-row :gutter="24">
              <!-- 当前季度信息 -->
              <a-col :span="12">
                <div class="quarter-info current">
                  <h3>当前季度额度</h3>
                  <div class="quarter-name">{{ currentQuarter }}</div>
                  <div class="quota-display">
                    <span class="quota-value">{{ currentQuotaValue }}</span>
                    <span class="quota-unit">额度/人</span>
                  </div>
                  <div class="update-time">上次更新: {{ currentQuotaUpdateTime }}</div>
                </div>
              </a-col>
              
              <!-- 下季度设置 -->
              <a-col :span="12">
                <div class="quarter-info next">
                  <h3>下季度额度</h3>
                  <div class="quarter-name">{{ nextQuarter }}</div>
                  <a-form layout="vertical" :model="formState">
                    <a-form-item>
                      <a-input-number 
                        v-model:value="formState.nextQuarterValue" 
                        :min="5" 
                        :max="30" 
                        :step="1" 
                        style="width: 100px"
                      />
                      <span class="quota-unit" style="margin-left: 8px">额度/人</span>
                    </a-form-item>
                    <a-form-item>
                      <a-button 
                        type="primary" 
                        @click="saveQuotaSetting"
                        :disabled="!isValueChanged"
                        :loading="submitLoading"
                      >
                        确认修改
                      </a-button>
                    </a-form-item>
                  </a-form>
                  <a-alert 
                    type="info" 
                    show-icon 
                    banner
                    style="margin-top: 8px"
                    message="修改后的额度将于下季度初自动生效"
                  />
                </div>
              </a-col>
            </a-row>
          </a-card>
        </div>
      </a-tab-pane>
      
      <a-tab-pane key="general" tab="通用设置">
        <div class="content-placeholder">
          <a-empty description="通用设置页面正在开发中" />
        </div>
      </a-tab-pane>
    </a-tabs>
  </div>
</template>

<script setup>
import { ref, reactive, computed, onMounted } from 'vue';
import { message } from 'ant-design-vue';

// 活动选项卡
const activeTab = ref('quota');

// 加载状态
const submitLoading = ref(false);

// 季度信息
const currentQuarter = ref('2023年第3季度 (7月-9月)');
const nextQuarter = ref('2023年第4季度 (10月-12月)');
const currentQuotaValue = ref(12);
const currentQuotaUpdateTime = ref('2023-06-15 10:30');

// 表单状态
const formState = reactive({
  nextQuarterValue: 12  // 初始值与当前值相同
});

// 计算值是否发生了变化
const isValueChanged = computed(() => {
  return formState.nextQuarterValue !== currentQuotaValue.value;
});

// 保存额度设置
const saveQuotaSetting = () => {
  if (formState.nextQuarterValue < 5 || formState.nextQuarterValue > 30) {
    message.error('额度必须在5至30之间');
    return;
  }
  
  submitLoading.value = true;
  
  // 模拟API请求
  setTimeout(() => {
    // 显示成功消息
    message.success('下季度额度设置已更新，将于下季度初生效');
    
    // 更新显示值(在实际应用中，这应该从API响应中获取)
    currentQuotaUpdateTime.value = new Date().toLocaleString('zh-CN', {
      year: 'numeric',
      month: '2-digit',
      day: '2-digit',
      hour: '2-digit',
      minute: '2-digit'
    }).replace(/\//g, '-');
    
    submitLoading.value = false;
  }, 800);
};

// 初始化
onMounted(() => {
  // 可以在这里加载初始数据
  // 这里使用的是静态数据，实际应用中应该从API获取
});
</script>

<style scoped>
.settings-container {
  padding: 24px 0;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h2 {
  margin: 0;
  font-size: 20px;
}

.quota-settings {
  padding: 0;
}

.quarter-info {
  padding: 16px;
  border-radius: 4px;
  height: 100%;
}

.quarter-info h3 {
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 16px;
}

.quarter-name {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  margin-bottom: 8px;
}

.quota-display {
  margin-bottom: 24px;
}

.quota-value {
  font-size: 32px;
  font-weight: bold;
  color: #1890ff;
}

.quota-unit {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  margin-left: 4px;
}

.update-time {
  font-size: 12px;
  color: rgba(0, 0, 0, 0.45);
}

.content-placeholder {
  background: #fff;
  border-radius: 4px;
  padding: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 400px;
}
</style> 